package com.test;

public class Account {
    //账户余额
    private int balance;
    /**
     * 设置初始余额
     */
    public Account(int balance) {
        this.balance = balance;
    }
    /**
     * 存钱
     */
    synchronized public void save(int money) {
        this.balance += money;

        System.out.println(Thread.currentThread().getName() + "存了" + money +
                "，余额是" + this.balance());
    }
    /**
     * 取钱
     */
    public synchronized void withdraw(int money) {
        this.balance -= money;
        System.out.println(Thread.currentThread().getName() + "取了" + money +
                "，余额是" + this.balance);
    }
    /**
     * 获取余额操作
     */
    public synchronized int balance() {
        return this.balance;
    }
}
